<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" src='../js/common.js'></script>
		<title>收货单位修改</title>
		<script type="text/javascript">
			var uid = window.localStorage["uid"];
			var loginname = window.localStorage["loginname"];
			var hid = getUrlParam('hid');
			addr_search()
			$(function(){
				$(".main_in_input_hide").click(function(){
                    $(".main_in_input_hide").hide();
                });
                
                $("body").on("click",".main_in_input_hide_main", function(){
                    var id = $(this).find('.main_in_input_hide_child').eq(0).html();
                    var name = $(this).find('.main_in_input_hide_child').eq(1).html();
                    $("#CustomerID").val(id);
                    $("#CustomerName").val(name);
                });
			});
			
			function doedit(){
				var CustomerName = $("#CustomerName").val();
                   var CustomerID = $("#CustomerID").val();
                   var passenger_fullname = $("#passenger_fullname").val();
                   var ContactTel = $("#passenger_contacttel").val();
                   var Contact = $("#passenger_contact").val();
                   var CityID = $("#CityID").val();
                   var CityName  = $("#CityName").val();
                   var Address = $("#passenger_address").val();
                   
                   if(CustomerName == ''){
                       alert("客户名称不能为空");
                        return false;
                   }
                   
                   if(passenger_fullname == ''){
                       alert("收货单位不能为空");
                        return false;
                   }
                   
                   if(CityName == ''){
                       alert("收货城市不能为空");
                        return false;
                   }
                   
                   if(Address == ''){
                       alert("详细地址不能为空");
                        return false;
                   }
                   
                   if(Contact == ''){
                       alert("联系人不能为空");
                        return false;
                   }
                   
                   if(ContactTel == ''){
                       alert("联系电话不能为空");
                        return false;
                   }
                   
                   var body = {"CityID":CityID,
                                "CustomerID":CustomerID,
                                "CustomerName":CustomerName,
                                "Warehouse":passenger_fullname,
                                "Addr":Address,
                                "Contact":Contact,
                                "CityName":CityName,
                                "ContactTel":ContactTel,
                                "Remark":"",
                                "Token":"22e8f734-dae9-494e-a743-4c4a64af4ce2",
                                "Demand":"",
                                "CPID":"11583-47254",
                                "NDID":"63599-70527",
                                "ReceiptDay":"","DeliveryDay":"",
                                "Type":2
                            }
                   
                   if(confirm("确认提交？")){
                   	var wt=plus.nativeUI.showWaiting();
                        $.ajax({
                            url: "http://api.unair.cn/api/AddressBL?id=" + hid,
                            type: "PUT",
                            data: body,
                            success: function (data) {
                                if(data != null){
                                    
                                    var w=plus.nativeUI.showWaiting("提交成功");
									w.onclose=function(){
										clearInterval(t);
									}
									var t=setInterval(function(){
										w.setTitle("提交成功");
										w.close();
										clicked("addr_search.html?x=2");
										clearInterval(t);
									},2000);
                                }else{
                                    alert("提交失败");
                                }
                                wt.close();
                            },
                            error: function (data) {
                                alert(JSON.stringify(data))
                                wt.close();
                            }

                        });
                    };
			}
			
			function cust_search(){
				var wt=plus.nativeUI.showWaiting();
				$(".main_in_input_hide").children().remove();
				var where =  "CreateBy = '"+loginname+"'";
            	var body = {"TableName": "Customer", "PKName": "ID", "PageSize": "999", 'pageCurrent': 1, "where": where};

                $.ajax({
                    url: "http://api.unair.cn/api/PagingQuery",
                    type: "POST",
                    data: body,
                    success: function(data) {
                        data = eval("(" + data.ResTable + ")");
                        var item = '';
                        $.each(data, function(k, v) {
                            v.Name = typeof (v.Name) == 'undefined' ? '' : v.Name;
                            v.Name = v.Name == null ? '' : v.Name;
                            v.ContactTel = typeof (v.ContactTel) == 'undefined' ? '' : v.ContactTel;
                            v.ContactTel = v.ContactTel == null ? '' : v.ContactTel;
                            v.Contact = typeof (v.Contact) == 'undefined' ? '' : v.Contact;
                            v.Contact = v.Contact == null ? '' : v.Contact;
                            item += "<div class='main_in_input_hide_main'>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.ID + "</div>" +
                                        "<div class='main_in_input_hide_child'>" + v.Name + "</div>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.Contact + "</div>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.ContactTel + "</div>" +
                                    "</div>";
                        });
                        $(".main_in_input_hide").append(item);
                        wt.close();
                    },
                    error: function(data) {
                        alert(JSON.stringify(data))
                        wt.close();
                    }
                });
                $(".main_in_input_hide").show();
			}
			
			function addr_search(){
				var body = {"TableName": "Address", "PKName": "ID", "PageSize": "15", 'pageCurrent': 1, "where": " ID = " + hid};
                $.ajax({
                    url: "http://api.unair.cn/api/PagingQuery",
                    type: "POST",
                    data: body,
                    success: function(data) {
                        data = eval("(" + data.ResTable + ")");
                        var item = '';
                        $.each(data, function(k, v) {
                            v.CustomerName = typeof (v.CustomerName) == 'undefined' ? '' : v.CustomerName;
                            v.CustomerName = v.CustomerName == null ? '' : v.CustomerName;
                            v.Warehouse = typeof (v.Warehouse) == 'undefined' ? '' : v.Warehouse;
                            v.Warehouse = v.Warehouse == null ? '' : v.Warehouse;
                            v.CityName = typeof (v.CityName) == 'undefined' ? '' : v.CityName;
                            v.CityName = v.CityName == null ? '' : v.CityName;
                            v.Addr = typeof (v.Addr) == 'undefined' ? '' : v.Addr;
                            v.Addr = v.Addr == null ? '' : v.Addr;
                            v.Name = typeof (v.Name) == 'undefined' ? '' : v.Name;
                            v.Name = v.Name == null ? '' : v.Name;
                            v.ContactTel = typeof (v.ContactTel) == 'undefined' ? '' : v.ContactTel;
                            v.ContactTel = v.ContactTel == null ? '' : v.ContactTel;
                            v.Contact = typeof (v.Contact) == 'undefined' ? '' : v.Contact;
                            v.Contact = v.Contact == null ? '' : v.Contact;
                            $("#CustomerName").val(v.CustomerName);
                            $("#CustomerID").val(v.CustomerID);
                            $("#passenger_fullname").val(v.Warehouse);
                            $("#passenger_contacttel").val(v.ContactTel);
                            $("#passenger_contact").val(v.Contact);
                            $("#CityID").val(v.CityID);
                            $("#CityName").val(v.CityName);
                            $("#passenger_address").val(v.Addr);
                        });
                    },
                    error: function(data) {
                        alert(JSON.stringify(data))
                    }
                    
                });
			}
		</script>
	</head>
	<body>
		<div class="app_head">
            <div class="app_prev bg_back" onclick="back()"><img src="../img/arrow.png" /></div>
            <div class="app_head_text">收货单位新增</div>
            <div class="app_prev"></div>
        </div>
        <div class="app_body">
            <div class="main_in_input">
                <div class="main_in_input_text_left">客户名称：</div>
                <div style="width: 40%;" class="main_in_input_input_right"><input type="text" id="CustomerName" value="" /></div>
                <div class="main_in_input_button_s2" onclick="cust_search()">请选择</div>
            </div>
            <div class="main_in_input_hide">
                
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">收货单位：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_fullname" value="" /></div>
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">收货城市：</div>
                <div class="main_in_input_input_right"><input type="text" class="select_city" id="CityName" value=""  readonly="true" /></div>
                <input type="hidden" name="CityID" class="select_city_id" id="CityID" />
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">详细地址：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_address" value="" /></div>
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">联系人：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_contact" value="" /></div>
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">联系电话：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_contacttel" value="" /></div>
            </div>
            <div style="background: #fff;width: 100%;height: 100px;">
                <div class="bg_submit" onclick="doedit()">提&nbsp;交</div>
                <div class="bg_back bg_back_class" onclick="back()">取&nbsp;消</div>
            </div>
        </div>
	</body>
</html>
